<?php

//提取phpwind整合的相关参数
function get_phpwind_config()
{
    $phpwindpath = dirname(dirname(__FILE__)) . '/data/phpwindapi.php';
    if (!file_exists($phpwindpath)) {
        return array('open' => 'off');
    }
    $content = file_get_contents($phpwindpath);
    $content = str_replace('<?php exit; ?>', '', $content);
    $post = unserialize($content);
    return $post;
}

//从phpwind检查注册用的用户名是否重复
function phpwind_check_user($uname, $config)
{
    $pwd = $config['pwd'];
    $checkurl = $config['phpdomain'] . '/hack/duoduo/comm.php?action=checkuser&user=' . urlencode($uname) . '&pwd=' . $pwd;
    $res = file_get_contents($checkurl);
    if (strstr($res, '---ok---') === false) {
        return -1;
    } else {
        return 1;
    }
}

//从phpwind检查注册用的邮箱是否重复
function phpwind_check_email($uname,$email, $config)
{
    $pwd = $config['pwd'];
    $checkurl = $config['phpdomain'] . '/hack/duoduo/comm.php?action=checkemail&uname=' . urlencode($uname) . '&email=' . $email . '&pwd=' . $pwd;
    $res = file_get_contents($checkurl);
    if (strstr($res, '---ok---') === false) {
        return -1;
    } else {
        return 1;
    }
}

//向phpwind注册
function reg_phpwind($user, $email, $userpwd, $config)
{
    $pwd = $config['pwd'];
    $checkurl = $config['phpdomain'] . '/hack/duoduo/comm.php?action=reg&user=' . urlencode($user) . '&email=' . $email . '&userpwd=' . $userpwd . '&pwd=' . $pwd;
    //echo $checkurl;exit;
    $res = file_get_contents($checkurl);
    if (strstr($res, '---ok---') === false) {
        return -1;
    } else {
        return 1;
    }
}

//改变phpwind的邮箱或或密码
function phpwind_change_email_pwd($user, $email, $userpwd, $config)
{
    $pwd = $config['pwd'];
    $checkurl = $config['phpdomain'] . '/hack/duoduo/comm.php?action=change&user=' . urlencode($user) . '&email=' . $email . '&userpwd=' . $userpwd . '&pwd=' . $pwd;
    $res = file_get_contents($checkurl);
    if (strstr($res, '---ok---') === false) {
        return -1;
    } else {
        return 1;
    }
}

//同步登录
function phpwind_login($name, $userpwd, $from, $config, $type=false)
{
    $pwd = $config['pwd'];
    if (!$from) {
        $from = 'center.php';
    }
    $time = time();
    $checkurl = $config['phpdomain'] . '/hack/duoduo/comm.php?action=login&user=' . urlencode($name) . '&userpwd=' . $userpwd . '&time=' . $time;
    //echo $checkurl;exit;
    if ($type == 1) {
        $checkurl = $config['phpdomain'] . '/hack/duoduo/comm.php?action=login&user=' . urlencode($name) . '&userpwd=' . $userpwd . '&type=1&time=' . $time;
    }
    
    if ($type == 2) {
        $msg = '正在注册，请稍候...';
    } else {
        $msg = '正在登录，请稍候...';
    }
    echo '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="1;url=' . $from . '">
<title></title>
';
    echo '<script src="' . $checkurl . '"></script>';
    echo '</head>
<body>
'.$msg.'
</body>
</html>';
}

//同步退出
function phpwind_quit($from, $config)
{
    $pwd = $config['pwd'];
    $time = time();
    $checkurl = $config['phpdomain'] . '/hack/duoduo/comm.php?action=quit&time=' . $time;
    echo '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="1;url=' . $from . '">
<title></title>
';
    echo '<script src="' . $checkurl . '"></script>';
    echo '</head>
<body>
正在退出，请稍候...
</body>
</html>';
}

?>
